package com.liu.controls;

import com.liu.keeppwd.SysState;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public abstract class MySpinnerDialog extends MySimpleDialog {

	String[] So;

	Context con;

	public abstract String OnSelect(int position);

	public MySpinnerDialog(Context con, String title, String[] So) {
		super(con, title, null);
		this.So = So;
		this.con = con;
		ListView lv = new ListView(con);
		lv.setCacheColorHint(Color.TRANSPARENT);
		lv.setAdapter(new BaseAdapter() {

			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				TextView text = new TextView(MySpinnerDialog.this.con);
				text.setTextSize(18);
				text.setText(MySpinnerDialog.this.So[position]);
				text.setTextColor(Color.rgb(33, 33, 33));
				text.setHeight(SysState.dp2pix(MySpinnerDialog.this.con, 40));
				text.setGravity(0x13);
				return text;
			}

			@Override
			public long getItemId(int position) {
				return position;
			}

			@Override
			public Object getItem(int position) {
				return MySpinnerDialog.this.So[position];
			}

			@Override
			public int getCount() {
				return MySpinnerDialog.this.So.length;
			}
		});
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				OnSelect(arg2);
				MySpinnerDialog.this.dismiss();
			}
		});
		this.setView(lv);
	}
}
